﻿using System;
using System.Timers;
using System.Text;

namespace LExperiment.LPublisher
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Timer pubTimer = new Timer())
            {
                pubTimer.Interval = 2000;

                using (LPublisher publisher = new LPublisher())
                {
                    int port = 6001;
                    publisher.Run(port);
                    Console.WriteLine("Begin working on port[{0}]",port.ToString());

                    int index = 0;
                    pubTimer.Elapsed += delegate(object source, ElapsedEventArgs evtargs)
                    {
                        ++index;
                        Console.WriteLine("\n################## {0}-th PUBLISH ##################", index.ToString());

                        string tmstring = DateTime.Now.ToLongTimeString();
                        publisher.Publish(Encoding.ASCII.GetBytes(tmstring));
                    };
                    pubTimer.Start();

                    Console.ReadLine();
                }// using Publisher
            }// using Timer
        }// Main
    }
}
